<?php

namespace App\Console\Commands;

use App\Jobs\GetUserNftJob;
use App\Services\HeliusService;
use Illuminate\Console\Command;

class GetUserUft extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:get-user-uft';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $helius = new HeliusService();
        //获取集合所有NFT
        $nfts = $helius->getCollectionNFTs(config('helius.rpc.collection_address'), 1);
        //限制处理的NFT数量（防止超时）
        collect($nfts)->chunk(100)->each(function ($nfts) {
            foreach ($nfts as $nft) {
                GetUserNftJob::dispatch($nft['id'], $nft['content']['metadata'], $nft['ownership']['owner'], $nft['content']['files'][0]['uri'])->onQueue('get_user_nft');
            }
        });

        //获取集合所有NFT
        $nfts = $helius->getCollectionNFTs(config('helius.rpc.collection_address'), 2);
        //限制处理的NFT数量（防止超时）
        collect($nfts)->chunk(100)->each(function ($nfts) {
            foreach ($nfts as $nft) {
                GetUserNftJob::dispatch($nft['id'], $nft['content']['metadata'], $nft['ownership']['owner'], $nft['content']['files'][0]['uri'])->onQueue('get_user_nft');
            }
        });
    }
}
